<?php
session_start();
require_once( 'master_db.php' );
 
$type = new M_master();
$user_id = $_SESSION['userid'];

if (isset($_POST['m'])  &&  $_POST['m']!=""){
    if ($_POST['m']== 'load'){
      $type->setTable($_POST['tb']);  
      $result=$type->loadData();
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'],$row['name'], $row['status']) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
      
    }else if ($_POST['m']=='add'){
        $ar = array();
		$ar['name']=  $_POST['t'];
		$ar['status'] = $_POST['s'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		$type->setTable($_POST['tb']);  
		$id=$type->InsertData($ar);
		
    }else if ($_POST['m']=='edit'){
		$ar = array();
		 
		$ar['name']=  $_POST['t'];
		$ar['status'] = $_POST['s'];
		$ar['updatedate'] =date( "Y/m/d H:i:s" );
		$ar['updateby'] = $user_id;
		$type->setTable($_POST['tb']);  
		$strcipt = $type->updateData($_POST['id'],$ar);
		// echo json_encode($strcipt);
	}
	else if ($_POST['m']=='del'){
         $id=$_POST['id'];
		 $type->setTable($_POST['tb']);  
		 $type->deleData($id);
		 
    }/// Age Criteria
	else if ($_POST['m']=='age'){
		$ar = array();
		
		list($day,$month) = explode('-',$_POST['dateAge']);// $_POST['date']."-".date("Y");
		
		$ar['age_date']=  date("Y")."/".$month."/".$day;
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		//$type->setTable("tb_master_age");  
		$id=$type->insertDataWithSql("SELECT age_date, createdate, createby from tb_master_age where 1=2",$ar);
	}
	else if ($_POST['m'] =='load_age'){
	  $result=$type->loadAge();
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['age_date'],$row['createdate'], $row['username']) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
	
	}
	else if ($_POST['m']=='afee'){
		$ar = array();
		list($d,$m,$y) = explode('/', $_POST['efdate']);
		$ar['effective_date']= $y."/".$m."/".$d;
		$ar['term'] = $_POST['term'];
		$ar['assets']=  $_POST['assets'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		$type->insertDataWithSql("SELECT effective_date , term , assets, createdate, createby from tb_master_fee where 1=2",$ar);
	}
	else if ($_POST['m']=='efee'){
		$ar = array();
		list($d,$m,$y) = explode('/', $_POST['efdate']);
		$ar['effective_date']= $y."/".$m."/".$d;
		$ar['term'] = $_POST['term'];
		$ar['assets']=  $_POST['assets'];
		$ar['updatedate'] =date( "Y/m/d H:i:s" );
		$ar['updateby'] = $user_id;
		$type->updateDataWithSql("SELECT  effective_date , term , assets, updatedate, updateby from tb_master_fee where id=".$_POST['id'],$ar);
		
	}
	else if ($_POST['m'] =='load_fee'){
	  $result=$type->loadFee();
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'], $row['effect_date'],$row['term'], $row['assets']) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
	
	}
}else{

}
 
?>